/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RekapForm.java
 *
 * Created on Nov 18, 2011, 8:55:23 PM
 */
package Com.TransaksiParkirdanLaporan.Com.Transaksi;

import Com.TransaksiParkirdanLaporan.Com.Laporan.LaporanController;
import Login.Karyawan;
import Login.LoginController;
import Login.MainForm;
import TabelModel.DataParkir_List;
import TabelModel.DataParkir_TableModel;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Tea-Nose
 */
public class RekapForm extends javax.swing.JFrame {

    String jamMasuk;

    /** Creates new form RekapForm */
    public RekapForm(String jamMasuk) throws IOException, SQLException {
        try {
            initComponents();
            this.jamMasuk = jamMasuk;
            try {
                LoginController.showKaryawan(label_Nama1, label_Nip1, label_Jabatan);
            } catch (Exception ex) {
                Logger.getLogger(RekapForm.class.getName()).log(Level.SEVERE, null, ex);
            }
            LaporanController.showDateAndClock(dateLabelRekap);
            TransaksiParkirController.noRekap(labelKodeRekapNilai);

            int jamIn = Integer.parseInt(jamMasuk.substring(0, 2));
            int menitIn = Integer.parseInt(jamMasuk.substring(3, 5));
            int detikIn = Integer.parseInt(jamMasuk.substring(6, 8));

            GregorianCalendar jam_Tekan_Logout = new GregorianCalendar();
            SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss am");
            String jam_Habis_Shift = dateFormat.format(jam_Tekan_Logout.getTime());

            int jamOut = Integer.parseInt(jam_Habis_Shift.substring(0, 2));
            int menitOut = Integer.parseInt(jam_Habis_Shift.substring(3, 5));
            int detikOut = Integer.parseInt(jam_Habis_Shift.substring(6, 8));

            int jumlah_Waktu_Shift = ((jamOut - jamIn) * 60 * 60) + ((menitOut - menitIn) * 60) + (detikOut - detikIn);

            if (jumlah_Waktu_Shift >= 60) {
                logout_Button.setEnabled(true);
            }


            List<DataParkir> dataparkirz = DataParkir_List.getDataParkir_List().getDataParkir(label_Nip1.getText(), jamMasuk);
            DataParkir_TableModel dataparkir_table = new DataParkir_TableModel(dataparkirz);
            rekapTable.setModel(dataparkir_table);

            TransaksiParkirController.hitungTotalRekap(rekapTable, label_JmlKend1, label_JmlPndpatan1);

        } catch (FileNotFoundException ex) {
            Logger.getLogger(RekapForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(RekapForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel6 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        label_Nip = new javax.swing.JLabel();
        label_Nama = new javax.swing.JLabel();
        label_JmlKend = new javax.swing.JLabel();
        label_JmlPndpatan = new javax.swing.JLabel();
        logout_Button = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        label_peringatan1 = new javax.swing.JLabel();
        label_peringatan2 = new javax.swing.JLabel();
        label_Nip1 = new javax.swing.JLabel();
        label_Nama1 = new javax.swing.JLabel();
        label_JmlKend1 = new javax.swing.JLabel();
        label_JmlPndpatan1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        scrollPane_tableScroll = new javax.swing.JScrollPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        rekapTable = new javax.swing.JTable();
        dateLabelRekap = new javax.swing.JLabel();
        labelKodeRekap = new javax.swing.JLabel();
        labelKodeRekapNilai = new javax.swing.JLabel();
        label_Jabatan = new javax.swing.JLabel();
        panel_Utama = new javax.swing.JPanel();
        panel_Title = new javax.swing.JPanel();
        label_Title = new javax.swing.JLabel();

        jLabel6.setText("jLabel6");

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        getContentPane().add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 50, 771, 10));

        label_Nip.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_Nip.setText("NIP");
        getContentPane().add(label_Nip, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 100, -1, -1));

        label_Nama.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_Nama.setText("Nama");
        getContentPane().add(label_Nama, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 80, -1, -1));

        label_JmlKend.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_JmlKend.setText("Jumlah Kendaraan Parkir");
        getContentPane().add(label_JmlKend, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 300, -1, -1));

        label_JmlPndpatan.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_JmlPndpatan.setText("Jumlah Pendapatan");
        getContentPane().add(label_JmlPndpatan, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 320, -1, -1));

        logout_Button.setText("Logout");
        logout_Button.setEnabled(false);
        logout_Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logout_ButtonActionPerformed(evt);
            }
        });
        getContentPane().add(logout_Button, new org.netbeans.lib.awtextra.AbsoluteConstraints(209, 396, -1, -1));

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });
        getContentPane().add(cancelButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(473, 396, -1, -1));

        label_peringatan1.setFont(new java.awt.Font("Tahoma", 2, 14));
        label_peringatan1.setText("Tombol \"Logout\" hanya muncul ketika shift Anda sudah habis");
        getContentPane().add(label_peringatan1, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 350, -1, -1));

        label_peringatan2.setFont(new java.awt.Font("Tahoma", 2, 14));
        label_peringatan2.setText("jika tidak maka klik tombol \"Cancel\" untuk kembali ke halaman sebelumnya");
        getContentPane().add(label_peringatan2, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 370, -1, -1));

        label_Nip1.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_Nip1.setText("NIP");
        getContentPane().add(label_Nip1, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 100, 90, -1));

        label_Nama1.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_Nama1.setText("Nama");
        getContentPane().add(label_Nama1, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 80, -1, -1));

        label_JmlKend1.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_JmlKend1.setText("Jumlah Kendaraan Parkir");
        getContentPane().add(label_JmlKend1, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 300, -1, -1));

        label_JmlPndpatan1.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_JmlPndpatan1.setText("Jumlah Pendapatan");
        getContentPane().add(label_JmlPndpatan1, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 320, -1, -1));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Data Parkir"));

        rekapTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "No. Parkir", "No. Polisi Kendaraan", "Jumlah Helm", "Kode Helm", "Tanggal Masuk", "Jam Masuk", "Biaya Parkir"
            }
        ));
        jScrollPane1.setViewportView(rekapTable);

        scrollPane_tableScroll.setViewportView(jScrollPane1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrollPane_tableScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(scrollPane_tableScroll, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 150, -1, -1));

        dateLabelRekap.setText("DATE/TIME");
        getContentPane().add(dateLabelRekap, new org.netbeans.lib.awtextra.AbsoluteConstraints(563, 66, 165, -1));

        labelKodeRekap.setFont(new java.awt.Font("Tahoma", 0, 14));
        labelKodeRekap.setText("Kode Rekap");
        getContentPane().add(labelKodeRekap, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, -1, -1));

        labelKodeRekapNilai.setFont(new java.awt.Font("Tahoma", 0, 14));
        labelKodeRekapNilai.setText("Kode Rekap");
        getContentPane().add(labelKodeRekapNilai, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 60, -1, -1));

        label_Jabatan.setFont(new java.awt.Font("Tahoma", 0, 14));
        label_Jabatan.setText("NIP");
        getContentPane().add(label_Jabatan, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 120, 90, -1));

        panel_Utama.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout panel_UtamaLayout = new javax.swing.GroupLayout(panel_Utama);
        panel_Utama.setLayout(panel_UtamaLayout);
        panel_UtamaLayout.setHorizontalGroup(
            panel_UtamaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 770, Short.MAX_VALUE)
        );
        panel_UtamaLayout.setVerticalGroup(
            panel_UtamaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 370, Short.MAX_VALUE)
        );

        getContentPane().add(panel_Utama, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 50, 770, 370));

        panel_Title.setBackground(new java.awt.Color(255, 255, 255));

        label_Title.setFont(new java.awt.Font("Tahoma", 1, 24));
        label_Title.setText("Rekap Data Parkir");

        javax.swing.GroupLayout panel_TitleLayout = new javax.swing.GroupLayout(panel_Title);
        panel_Title.setLayout(panel_TitleLayout);
        panel_TitleLayout.setHorizontalGroup(
            panel_TitleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_TitleLayout.createSequentialGroup()
                .addContainerGap(283, Short.MAX_VALUE)
                .addComponent(label_Title)
                .addGap(272, 272, 272))
        );
        panel_TitleLayout.setVerticalGroup(
            panel_TitleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_TitleLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(label_Title)
                .addContainerGap())
        );

        getContentPane().add(panel_Title, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 770, 50));

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-787)/2, (screenSize.height-458)/2, 787, 458);
    }// </editor-fold>//GEN-END:initComponents

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        try {
            DataRekap.getConnection().deleteDataRekap(labelKodeRekapNilai.getText());
            TransaksiParkirController.openLayananMasuk(this, jamMasuk);
        } catch (SQLException ex) {
            Logger.getLogger(RekapForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(RekapForm.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_cancelButtonActionPerformed

    private void logout_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logout_ButtonActionPerformed
        // TODO add your handling code here:
        DataRekap dataRekap = new DataRekap();

        GregorianCalendar date_Rekap = new GregorianCalendar();
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
        String tanggal_Rekap = dateFormat.format(date_Rekap.getTime());

        try {
            dataRekap.setTanggalRekap(tanggal_Rekap);
            dataRekap.setJumlahKendaraanPerShift(Integer.parseInt(label_JmlKend1.getText()));
            dataRekap.setJumlahPendapatanPerShift(Double.parseDouble(label_JmlPndpatan1.getText().substring(2).replace(".", "").replace(",00", "")));
            dataRekap.setKodeRekap(labelKodeRekapNilai.getText());
            dataRekap.setIdKaryawan(label_Nip1.getText());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex.getMessage());
        }

        try {
            DataRekap.getConnection().simpanDataRekap(dataRekap);
        } catch (Exception ex) {
        }
        try {
            // TODO add your handling code here:
            Karyawan.logout();
            this.setVisible(false);
            LoginController.openLoginForm();
        } catch (Exception ex) {
        }
    }//GEN-LAST:event_logout_ButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel dateLabelRekap;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel labelKodeRekap;
    private javax.swing.JLabel labelKodeRekapNilai;
    private javax.swing.JLabel label_Jabatan;
    private javax.swing.JLabel label_JmlKend;
    private javax.swing.JLabel label_JmlKend1;
    private javax.swing.JLabel label_JmlPndpatan;
    private javax.swing.JLabel label_JmlPndpatan1;
    private javax.swing.JLabel label_Nama;
    private javax.swing.JLabel label_Nama1;
    private javax.swing.JLabel label_Nip;
    private javax.swing.JLabel label_Nip1;
    private javax.swing.JLabel label_Title;
    private javax.swing.JLabel label_peringatan1;
    private javax.swing.JLabel label_peringatan2;
    private javax.swing.JButton logout_Button;
    private javax.swing.JPanel panel_Title;
    private javax.swing.JPanel panel_Utama;
    private javax.swing.JTable rekapTable;
    private javax.swing.JScrollPane scrollPane_tableScroll;
    // End of variables declaration//GEN-END:variables
}
